package 模拟;

/**
 * @author 帅小伙
 * @date 2022/1/23
 * @description
 */
public class Demo02 {

    public static void main(String[] args) {
        numberOfArrays(new int[]{1,-3,4},1,6);
    }


    public static int numberOfArrays(int[] differences, int lower, int upper) {
        int n = differences.length;
        int i = lower;
        int max = i;
        boolean flag = true;
        while(true){
            max = i;
            int t = i;
            for (int j = 0; j < n; j++) {
                t += differences[j];
                max = Math.max(max, t);
                if (t > upper || t < lower) {
                    flag = false;
                    break;
                }
            }
            i++;
            if(flag || i > upper)break;
            flag  = true;
        }

        if(flag)return upper - max+1;
        else return 0;

    }
}
